package com.community.web.user.controller.visit;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.community.common.login.LoginUserHolder;
import com.community.common.result.Result;
import com.community.model.entity.Visitor;
import com.community.web.user.service.VisitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "访客模块")
@RestController
@RequestMapping("/user/visitor")
public class VisitorController {

    @Autowired
    private VisitorService service;

    @ApiOperation("添加访客")
    @PostMapping()
    public Result addVisitor(@RequestBody Visitor visitor){
        Long userId = LoginUserHolder.getLoginUser().getUserId();
        visitor.setUserId(userId.intValue());
        visitor.setVisitorStatus(0);
        service.save(visitor);
        return Result.ok();
    }

    @ApiOperation("根据用户id查询访客列表")
    @GetMapping()
    public Result<List<Visitor>> getVisitorList(){
        Long userId = LoginUserHolder.getLoginUser().getUserId();
        LambdaQueryWrapper<Visitor> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Visitor::getUserId, userId);
        List<Visitor> list = service.list(queryWrapper);
        return Result.ok(list);
    }

}
